package Com.HupochuanAdmin.Uil.Do;

import java.util.Hashtable;
import java.util.List;

import Com.Hupochuan.Uil.Servlet.DoRunServlet;
import Com.Hupochuan.Vo.Actor;
import Com.Hupochuan.Vo.MovieActor;
import Com.HupochuanAdmin.Dal.Tab.ActorTab;
import Com.HupochuanAdmin.Dal.Tab.MovieActorTab;
import Com.HupochuanAdmin.Uil.Util.AdminParameter;
import Com.Tester.Tester;

@SuppressWarnings("serial")
public class ActorListDo extends DoRunServlet{
	public void doRun(){
		
		//打印测试
		Tester.print("打印测试 - ActorListDo");
		
		//获得数据
		String searchType = this.getDoTool().getUrlChinesePara("searchType");
		String searchKey = this.getDoTool().getUrlChinesePara("searchKey");
		String state = this.getDoTool().getPara("state");
		String showRow = this.getDoTool().getPara("showRow");
		long pageNo = this.getDoTool().getLongPara("pageNo");
		
		//获得内存参数
		long pageSize = AdminParameter.getObject().getActorListPageSize();
		String order = AdminParameter.getObject().getActorListOrder();
		boolean asc = AdminParameter.getObject().isActorListAsc();
		Hashtable<String,Boolean> showCol = AdminParameter.getObject().getActorListShowCol();
		
		long infoCount = ActorTab.getObject().findActorCount(searchType,searchKey,showRow);
		
		//初始化页数
		long pageCount = 1;
		
		//计算页数
		if(infoCount != 0){
			//如果信息数量正好满页
			if(infoCount % pageSize == 0){
				pageCount = infoCount / pageSize; 
			}
			//如果信息数量不满页
			else{
				pageCount = infoCount / pageSize + 1;
			}
		}
		
		if(pageNo > pageCount){
			pageNo = pageCount;
		}
		else if(pageNo < 1){
			pageNo = 1;
		}
		
		//获得演员列表
		List<Actor> actorList = ActorTab.getObject().findActorList(searchType,searchKey,showRow,order,asc,pageNo,pageSize);
		
		//如果要 显示电影列表
		if(showCol.get("showMovieInfo") && showCol.get("showMovie")){
			//遍历演员列表 获得每个演员的电影列表
			for(Actor actor : actorList){
				List<MovieActor> movieActorList = MovieActorTab.getObject().findMovieActorListByActorId(actor.getId());
				actor.setMovieActorList(movieActorList);
			}
		}
		//设置数据
		this.getDoTool().setAttr("searchType", searchType);
		this.getDoTool().setAttr("searchKey", searchKey);
		this.getDoTool().setAttr("state", state);
		this.getDoTool().setAttr("showRow", showRow);
		this.getDoTool().setAttr("order", order);
		this.getDoTool().setAttr("asc", asc);
		this.getDoTool().setAttr("infoCount",infoCount);
		this.getDoTool().setAttr("pageSize", pageSize);
		this.getDoTool().setAttr("pageNo", pageNo);
		this.getDoTool().setAttr("pageCount", pageCount);
		this.getDoTool().setAttr("actorList", actorList);
		this.getDoTool().setAttr("showCol", showCol);
		
		//转发jsp页面
		this.getDoTool().forward("/jsp/admin/actorList.jsp");
	}
}
